<?php
namespace app\api\controller;
use think\Input;
use think\Controller;
use app\admin\model\Users;
use app\common\controller\Base;
class Upload extends Base{
	public function image(){
		// 获取上传文件表单字段名
        $fileKey = array_keys(request()->file());
        // 获取表单上传文件
        $file = request()->file($fileKey['0']);
        // 移动到框架应用根目录/public/uploads/ 目录下
        $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
        if($info){
            $result['code'] = 0;
            $result['info'] = lang('Upload success');
            $path=str_replace('\\','/',$info->getSaveName());
            $result['url'] = url('/uploads/'. $path,[],false,true);
            return $result;
        }else{
            // 上传失败获取错误信息
            $result['code'] =-1;
            $result['info'] = lang('Upload failure');
            $result['url'] = '';
            return $result;
        }
	}
	public function expand($network_id=null){
		$result = $this->image();
		if($result['code'] == 0 && $network_id > 0){
			db('networks')->where(['id'=>$network_id])->update(['media'=>$result['url']]);
		}
		return $result;
	}
}